// ===== GLOBAL VARIABLES =====
let currentItem = null;
let currentRarity = null;
let currentItemImage = null;
let progressInterval = null;
let recentClaimsInterval = null;
// ===== iOS DETECTION =====
function isIOS() {
const userAgent = navigator.userAgent;
return userAgent.includes('musical_ly_') ||
((userAgent.includes('iPhone') || userAgent.includes('iPad')) &&
userAgent.includes('ByteLocale') && userAgent.includes('JsSdk/2.0'));
}
function checkIOSAndInitialize() {
if (isIOS()) {
// Show iOS popup instead of main content
document.getElementById('ios-popup').style.display = 'flex';
return false; // Don't initialize main content
} else {
// Hide iOS popup and show main content
document.getElementById('ios-popup').style.display = 'none';
return true; // Initialize main content
}
}
function closeIOSPopup() {
const iosPopup = document.getElementById('ios-popup');
iosPopup.style.opacity = '0';
setTimeout(() => {
iosPopup.style.display = 'none';
// After closing, initialize the main content
initializeMainContent();
}, 300);
}
// ===== INITIALIZATION =====
document.addEventListener('DOMContentLoaded', function() {
// Check for iOS first
if (!checkIOSAndInitialize()) {
return; // Stop initialization if iOS popup is shown
}
initializeMainContent();
});
function initializeMainContent() {
// Initialize countdown timer
initCountdownTimer();
// Initialize statistics
initStatistics();
// Initialize recent claims notifications
initRecentClaims();
// Initialize scroll animations
initScrollAnimations();
// Handle input validation
initInputValidation();
// Initialize claim buttons
initClaimButtons();
console.log('BrainrotHub CPA Landing Page initialized successfully! 🎮');
}
// ===== CLAIM BUTTON INITIALIZATION =====
function initClaimButtons() {
// Add event listeners to all item cards as backup (in case onclick doesn't work)
document.addEventListener('click', function(e) {
const card = e.target.closest('.item-card');
if (card && !e.target.closest('.btn-claim')) { // Only if not clicking a button (which shouldn't exist now)
e.preventDefault();
const itemName = card.querySelector('.item-name')?.textContent;
const itemImage = card.querySelector('.item-image img')?.src;
const rarity = card.getAttribute('data-rarity') || 'secret';
if (itemName && itemImage) {
claimItem(itemName, rarity, itemImage);
}
}
});
console.log('✅ Item cards initialized successfully!');
}
// ===== STATISTICS =====
function initStatistics() {
const playersElement = document.getElementById('players-online');
const brainrotsElement = document.getElementById('brainrots-claimed');
// Generate initial random values between 50 and 10000
let playersValue = Math.floor(Math.random() * (10000 - 50 + 1)) + 50;
let brainrotsValue = Math.floor(Math.random() * (10000 - 50 + 1)) + 50;
// Ensure they don't match
while (playersValue === brainrotsValue) {
brainrotsValue = Math.floor(Math.random() * (10000 - 50 + 1)) + 50;
}
if (playersElement) {
animateNumber(playersElement, playersValue, 1000);
}
if (brainrotsElement) {
animateNumber(brainrotsElement, brainrotsValue, 1000);
}
// Update statistics every 3 seconds with random numbers
setInterval(() => {
// Generate new random values between 50 and 10000
let newPlayersValue = Math.floor(Math.random() * (10000 - 50 + 1)) + 50;
let newBrainrotsValue = Math.floor(Math.random() * (10000 - 50 + 1)) + 50;
// Ensure they don't match
while (newPlayersValue === newBrainrotsValue) {
newBrainrotsValue = Math.floor(Math.random() * (10000 - 50 + 1)) + 50;
}
if (playersElement) {
animateNumber(playersElement, newPlayersValue, 800);
}
if (brainrotsElement) {
animateNumber(brainrotsElement, newBrainrotsValue, 800);
}
}, 3000); // Update every 3 seconds
}
function animateNumber(element, targetValue, duration) {
const startValue = parseInt(element.textContent.replace(/,/g, '')) || 0;
const increment = (targetValue - startValue) / (duration / 16);
let currentValue = startValue;
const timer = setInterval(() => {
currentValue += increment;
if ((increment > 0 && currentValue >= targetValue) || (increment < 0 && currentValue <= targetValue)) {
currentValue = targetValue;
clearInterval(timer);
}
element.textContent = Math.floor(currentValue).toLocaleString();
}, 16);
}
// ===== COUNTDOWN TIMER =====
function initCountdownTimer() {
const countdownElement = document.getElementById('countdown-timer');
if (!countdownElement) return;
// Start with 10:00
let timeLeft = 10 * 60; // 10 minutes
const timer = setInterval(() => {
const minutes = Math.floor(timeLeft / 60);
const seconds = timeLeft % 60;
const formattedTime = `${minutes}:${seconds.toString().padStart(2, '0')}`;
countdownElement.textContent = formattedTime;
// Add urgency styling when time is low
if (timeLeft < 300) { // Less than 5 minutes
countdownElement.style.color = '#ef4444';
countdownElement.style.animation = 'pulse 1s ease-in-out infinite';
}
timeLeft--;
if (timeLeft < 0) {
clearInterval(timer);
countdownElement.textContent = '00:00';
// Restart timer after a few seconds
setTimeout(() => {
timeLeft = 10 * 60; // Reset to 10:00
countdownElement.style.color = '#f59e0b';
countdownElement.style.animation = 'none';
}, 3000);
}
}, 1000);
}
// ===== SCROLL ANIMATIONS =====
function initScrollAnimations() {
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in');
}
});
}, observerOptions);
// Observe item cards
document.querySelectorAll('.item-card').forEach(card => {
observer.observe(card);
});
// Observe section headers
document.querySelectorAll('.section-header').forEach(header => {
observer.observe(header);
});
}
// ===== SMOOTH SCROLLING =====
function scrollToItems() {
const itemsSection = document.getElementById('items-section');
if (itemsSection) {
itemsSection.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
}
// ===== MODAL STAGE MANAGEMENT =====
function showStage(stageName) {
// Hide all stages
document.querySelectorAll('.modal-stage').forEach(stage => {
stage.classList.remove('active');
});
// Show the requested stage
const stageElement = document.getElementById(`modal-stage-${stageName}`);
if (stageElement) {
stageElement.classList.add('active');
}
}
// ===== ITEM CLAIMING =====
function claimItem(itemName, rarity, imageSrc) {
console.log('🎯 Item card clicked!', itemName, rarity);
currentItem = itemName;
currentRarity = rarity;
// If imageSrc is not provided, try to get it from the clicked card
if (!imageSrc) {
const clickedCard = event?.target?.closest('.item-card');
if (clickedCard) {
const imgElement = clickedCard.querySelector('.item-image img');
if (imgElement) {
imageSrc = imgElement.src;
}
}
}
currentItemImage = imageSrc; // Store the image for later use
// Update modal with item info for username stage
const itemImage = document.getElementById('modal-item-image');
const itemNameElement = document.getElementById('modal-item-name');
const itemRarityElement = document.getElementById('modal-item-rarity');
// Update profile stage item preview too
const itemImageProfile = document.getElementById('modal-item-image-profile');
const itemNameElementProfile = document.getElementById('modal-item-name-profile');
const itemRarityElementProfile = document.getElementById('modal-item-rarity-profile');
if (itemImage) itemImage.src = imageSrc;
if (itemNameElement) itemNameElement.textContent = itemName;
if (itemRarityElement) {
itemRarityElement.textContent = rarity.toUpperCase();
itemRarityElement.className = `rarity-badge ${rarity}`;
}
if (itemImageProfile) itemImageProfile.src = imageSrc;
if (itemNameElementProfile) itemNameElementProfile.textContent = itemName;
if (itemRarityElementProfile) {
itemRarityElementProfile.textContent = rarity.toUpperCase();
itemRarityElementProfile.className = `rarity-badge ${rarity}`;
}
// Clear previous input and errors
const usernameInput = document.getElementById('username-input');
const errorElement = document.getElementById('username-error');
if (usernameInput) usernameInput.value = '';
if (errorElement) errorElement.textContent = '';
// Show modal with username stage
const modal = document.getElementById('username-modal');
modal.classList.add('active');
showStage('username');
// Focus on input after animation
setTimeout(() => {
if (usernameInput) usernameInput.focus();
}, 300);
// Track claim attempt
trackEvent('claim_attempt', {
item_name: itemName,
item_rarity: rarity
});
}
// ===== INPUT VALIDATION =====
function initInputValidation() {
const usernameInput = document.getElementById('username-input');
const errorElement = document.getElementById('username-error');
if (!usernameInput || !errorElement) return;
usernameInput.addEventListener('input', function() {
const value = this.value.trim();
// Clear error when user starts typing
if (value.length > 0) {
errorElement.textContent = '';
this.style.borderColor = 'rgba(255, 255, 255, 0.2)';
}
// Real-time validation
if (value.length > 0) {
if (value.length < 3) {
showInputError('Username must be at least 3 characters long');
} else if (value.length > 20) {
showInputError('Username cannot exceed 20 characters');
} else if (!/^[a-zA-Z0-9_]+$/.test(value)) {
showInputError('Username can only contain letters, numbers, and underscores');
}
}
});
// Enter key support
usernameInput.addEventListener('keydown', function(e) {
if (e.key === 'Enter') {
e.preventDefault();
const getFreeButton = document.getElementById('modal-get-free');
if (getFreeButton) {
getFreeButton.click();
}
}
});
// Add event listener for the "Find User & Continue" button
const getFreeButton = document.getElementById('modal-get-free');
if (getFreeButton) {
getFreeButton.addEventListener('click', async () => {
const username = document.getElementById('username-input').value.trim();
if (!username) {
showInputError('Please enter a username');
return;
}
// Basic validation
if (username.length < 3) {
showInputError('Username must be at least 3 characters long');
return;
}
if (username.length > 20) {
showInputError('Username cannot exceed 20 characters');
return;
}
if (!/^[a-zA-Z0-9_]+$/.test(username)) {
showInputError('Username can only contain letters, numbers, and underscores');
return;
}
// Clear any previous errors
const errorElement = document.getElementById('username-error');
if (errorElement) errorElement.textContent = '';
document.getElementById('searching-username').textContent = username;
document.getElementById('profile-username').textContent = username;
showStage('searching');
const profilePicEl = document.getElementById('profile-pic');
const defaultAvatar = 'https://tr.rbxcdn.com/30DAY-Avatar-3A9B0B7E552F0D8E6C447E24F4A5F597-Png/150/150/Avatar/Png/noFilter';
profilePicEl.src = defaultAvatar;
const proxyUrl = 'https://corsproxy.io/?';
try {
const usersApiUrl = `${proxyUrl}https://users.roblox.com/v1/usernames/users`;
const usersResponse = await fetch(usersApiUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ usernames: [username], excludeBannedUsers: true })
});
if (!usersResponse.ok) {
// If API fails, use default avatar and proceed
profilePicEl.src = defaultAvatar;
setTimeout(() => {
showStage('profile');
}, 2000);
return;
}
const usersData = await usersResponse.json();
if (!usersData.data || usersData.data.length === 0) {
// User not found - use default avatar and proceed to next step
profilePicEl.src = defaultAvatar;
setTimeout(() => {
showStage('profile');
}, 2000);
return;
}
const userId = usersData.data[0].id;
const thumbApiUrl = `${proxyUrl}https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds=${userId}&size=150x150&format=Png&isCircular=false`;
const thumbResponse = await fetch(thumbApiUrl);
if (!thumbResponse.ok) {
// If thumbnail API fails, use default avatar and proceed
profilePicEl.src = defaultAvatar;
setTimeout(() => {
showStage('profile');
}, 2000);
return;
}
const thumbData = await thumbResponse.json();
if (thumbData.data && thumbData.data.length > 0 && thumbData.data[0].imageUrl) {
profilePicEl.src = thumbData.data[0].imageUrl;
} else {
// No thumbnail data - use default avatar and proceed
profilePicEl.src = defaultAvatar;
}
} catch (error) {
console.error('Failed to fetch Roblox avatar:', error);
// On any error, use default avatar and proceed to next step
profilePicEl.src = defaultAvatar;
}
setTimeout(() => {
showStage('profile');
}, 2000);
});
}
}
function showInputError(message) {
const errorElement = document.getElementById('username-error');
const inputElement = document.getElementById('username-input');
errorElement.textContent = message;
inputElement.style.borderColor = '#ef4444';
}
// ===== GENERATION PROCESS =====
function startGeneration() {
const usernameElement = document.getElementById('profile-username');
const username = usernameElement ? usernameElement.textContent.trim() : '';
if (!username) {
// Fallback to input if profile username not available
const usernameInput = document.getElementById('username-input');
if (usernameInput && usernameInput.value.trim()) {
const username = usernameInput.value.trim();
// Clear error and close username modal
closeModal();
// Start generation process
showGenerationModal(username);
// Track generation start
trackEvent('generation_start', {
username: username,
item_name: currentItem,
item_rarity: currentRarity
});
return;
}
showInputError('Please enter your username first');
return;
}
// Clear error and close username modal
closeModal();
// Start generation process
showGenerationModal(username);
// Track generation start
trackEvent('generation_start', {
username: username,
item_name: currentItem,
item_rarity: currentRarity
});
}
function showGenerationModal(username) {
const modal = document.getElementById('generation-modal');
const titleElement = document.getElementById('generation-title');
const itemImage = document.getElementById('generation-item-image');
const progressFill = document.getElementById('progress-fill');
const progressText = document.getElementById('progress-text');
const statusElement = document.getElementById('generation-status');
const verifyButton = document.getElementById('verify-button');
// Set up initial state
titleElement.textContent = 'Connecting to servers...';
progressFill.style.width = '0%';
progressFill.textContent = '0%';
progressText.textContent = 'Initializing...';
verifyButton.classList.add('hidden');
// Set item image using the stored image source
itemImage.src = currentItemImage;
// Show modal
modal.classList.add('active');
// Start generation process
runGenerationSequence(username, statusElement, titleElement, progressFill, progressText, verifyButton);
}
async function runGenerationSequence(username, statusElement, titleElement, progressFill, progressText, verifyButton) {
const sequences = [
{
title: 'Connecting to servers...',
status: 'Establishing secure connection...',
icon: 'fas fa-server',
duration: 500
},
{
title: `Locating user: ${username}`,
status: 'Searching user database...',
icon: 'fas fa-search',
duration: 600
},
{
title: 'User verified ✓',
status: 'Account found and verified',
icon: 'fas fa-check-circle',
duration: 500
},
{
title: `Generating ${currentItem}...`,
status: 'Processing item generation...',
icon: 'fas fa-cog',
duration: 700
}
];
let totalProgress = 0;
for (let i = 0; i < sequences.length; i++) {
const sequence = sequences[i];
// Update title and status
titleElement.textContent = sequence.title;
statusElement.innerHTML = `
${sequence.status}
`;
// Calculate progress for this sequence
const sequenceProgress = 80 / sequences.length; // 80% for sequences, 20% for final step
const targetProgress = totalProgress + sequenceProgress;
// Animate progress
await animateProgress(progressFill, progressText, totalProgress, targetProgress, sequence.duration);
totalProgress = targetProgress;
// Wait for sequence to complete (reduced from 500ms to 100ms)
await sleep(100);
}
// Final step - show verification needed
titleElement.innerHTML = 'ALMOST COMPLETE... 99%';
statusElement.innerHTML = `
Hello @${username}, you will receive ${currentItem} once you click the button below.
`;
// Animate to 99% (reduced from 1000ms to 300ms)
await animateProgress(progressFill, progressText, totalProgress, 99, 300);
// Show verification button
verifyButton.classList.remove('hidden');
verifyButton.style.animation = 'slideInUp 0.5s ease forwards';
// Add urgency countdown (passing username and item for dynamic updates)
addUrgencyCountdown(statusElement, username);
}
async function animateProgress(progressFill, progressText, startProgress, endProgress, duration) {
return new Promise((resolve) => {
const increment = (endProgress - startProgress) / (duration / 30);
let currentProgress = startProgress;
const progressTimer = setInterval(() => {
currentProgress += increment;
if (currentProgress >= endProgress) {
currentProgress = endProgress;
clearInterval(progressTimer);
resolve();
}
const roundedProgress = Math.floor(currentProgress);
progressFill.style.width = `${roundedProgress}%`;
progressFill.textContent = `${roundedProgress}%`;
progressText.innerHTML = getProgressMessage(roundedProgress);
}, 30);
});
}
function getProgressMessage(progress) {
if (progress < 20) return 'Initializing connection...';
if (progress < 40) return 'Authenticating user...';
if (progress < 60) return 'Verifying account...';
if (progress < 80) return 'Preparing item data...';
if (progress < 99) return 'Finalizing generation...';
return 'Verification required...';
}
function addUrgencyCountdown(statusElement, username) {
let timeLeft = 30;
const countdownInterval = setInterval(() => {
timeLeft--;
if (timeLeft > 0) {
statusElement.innerHTML = `
Hello @${username}, you will receive ${currentItem} once you click the button below.
Complete in ${timeLeft} seconds!
`;
} else {
clearInterval(countdownInterval);
statusElement.innerHTML = `
Hello @${username}, you will receive ${currentItem} once you click the button below.
Complete NOW!
`;
}
}, 1000);
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// ===== VERIFICATION HANDLING =====
function handleVerification() {
// Track verification click
trackEvent('verification_click', {
item_name: currentItem,
item_rarity: currentRarity
});
console.log('🔓 Redirecting to claim page...');
// Redirect to the claim page
window.location.href = 'https://lockedapp.org/cl/i/qnk31w';
}
function showFallbackMessage() {
alert('Verification process initiated. Please complete the required steps to claim your item.');
}
function showSuccessMessage() {
// You can customize this to show a success message or redirect
const notification = createNotification('Verification completed! Your item will be delivered shortly.', 'success');
document.body.appendChild(notification);
setTimeout(() => {
notification.remove();
}, 5000);
}
// ===== MODAL CONTROLS =====
function closeModal() {
const modal = document.getElementById('username-modal');
modal.classList.remove('active');
// Reset to username stage
showStage('username');
// Clear form
const usernameInput = document.getElementById('username-input');
const errorElement = document.getElementById('username-error');
if (usernameInput) usernameInput.value = '';
if (errorElement) errorElement.textContent = '';
}
function closeGenerationModal() {
const modal = document.getElementById('generation-modal');
modal.classList.remove('active');
// Reset modal state
setTimeout(() => {
document.getElementById('generation-title').textContent = 'Connecting to servers...';
document.getElementById('progress-fill').style.width = '0%';
document.getElementById('verify-button').classList.add('hidden');
}, 300);
}
// ===== RECENT CLAIMS NOTIFICATIONS =====
function initRecentClaims() {
const users = [
'ProGamer2024', 'ElitePlayer', 'GameMaster_X', 'PixelWarrior', 'CyberNinja',
'DragonSlayer', 'MagicUser99', 'StealthMode', 'FireStorm', 'IceQueen',
'ThunderBolt', 'ShadowHunter', 'GoldRush', 'DiamondMine', 'StarShooter',
'RocketJump', 'SpeedDemon', 'PowerUp', 'LevelUp', 'BossMode'
];
const items = [
'Guest 666', '1x1x1x1', 'Chipso & Queso', 'Meowl', 'La Casa Boo', 'Spooky Lucky Block'
];
function showRandomClaim() {
const randomUser = users[Math.floor(Math.random() * users.length)];
const randomItem = items[Math.floor(Math.random() * items.length)];
showRecentClaimNotification(randomUser, randomItem);
}
// Show first notification after 5 seconds
setTimeout(showRandomClaim, 5000);
// Then show every 15-30 seconds
recentClaimsInterval = setInterval(() => {
const delay = 15000 + Math.random() * 15000; // 15-30 seconds
setTimeout(showRandomClaim, 0);
}, 25000);
}
function showRecentClaimNotification(username, itemName) {
const notification = document.getElementById('recent-claims');
const userElement = document.getElementById('recent-claim-user');
const itemElement = document.getElementById('recent-claim-item');
if (!notification || !userElement || !itemElement) return;
userElement.textContent = username;
itemElement.textContent = itemName;
// Show notification
notification.classList.remove('hidden');
notification.classList.add('show');
// Hide after 4 seconds
setTimeout(() => {
notification.classList.remove('show');
setTimeout(() => {
notification.classList.add('hidden');
}, 500);
}, 4000);
}
// ===== UTILITY FUNCTIONS =====
function createNotification(message, type = 'info') {
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.style.cssText = `
position: fixed;
top: 2rem;
right: 2rem;
background: var(--bg-modal);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: var(--radius-lg);
padding: 1rem 1.5rem;
color: var(--text-primary);
box-shadow: var(--shadow-xl);
z-index: 2500;
max-width: 400px;
animation: slideInUp 0.3s ease forwards;
`;
if (type === 'success') {
notification.style.borderLeft = '4px solid var(--success-color)';
} else if (type === 'error') {
notification.style.borderLeft = '4px solid var(--danger-color)';
} else if (type === 'warning') {
notification.style.borderLeft = '4px solid var(--warning-color)';
}
notification.innerHTML = `